#include <iostream>
#include <string>
using namespace std;

int dp[1003][1003];

int longestPalindromeSubseq(string s) {
    int n = s.length();
    
    for (int i = 0; i < n; i++) dp[i][i] = 1;
    
    for (int i = n - 1; i >= 0; i--) {
        for (int j = i+1; j <n ; j++) {
            if (s[i] == s[j])
                dp[i][j] = dp[i + 1][j - 1] + 2;
            else
                dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]);
        }
    }
    
    return dp[0][n - 1];
}

int main() {
    string s = "bbbab";
    int ans = longestPalindromeSubseq(s);
    cout << ans << endl;
    return 0;
}